/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOImpl;

import Exception.DBConnectionException;
import POJO.Student;
import Util.DBUtils;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class StudentImpl extends BaseImpl {

    @Override
    public List<?> findAll() {
        
        List<Student> listStudents = new ArrayList<Student>();
        try{
            Connection con =  DBUtils.getConnection();
            
            String query = "SELECT * FROM [dbo].[Student] ";
            
            Statement stmt =  con.createStatement();
            ResultSet rs =  stmt.executeQuery(query);
            
            
            while(rs.next()){
                int id = rs.getInt("id");
                String name =  rs.getString("name");
                String description = rs.getString("description");
                int classId = rs.getInt("classId");
                
                Student std  = new Student(id, name, description, classId);
                listStudents.add(std);
            }
            
        }
        catch (SQLException ex) {
            Logger.getLogger(StudentImpl.class.getName()).log(Level.SEVERE, null, ex);
        }        catch(DBConnectionException dbException){
            String errMsg = dbException.getErrMessage();
            
        }
        
        return listStudents;
    }
    
}
